home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
debugc.arc
/
DEBUG.C
Wrap
Text File
|
1986-03-13
|
11KB
|
334 lines
<TAU>DEBUG.H:
50 lines
/*----------------------------DEBUG.H--------------------------------------
* DEBUG.H This header file contains the statements necessary for the
* conditional compilation of debug statements, and a typedef
* us
ed by the inkey() function.
*------------------------------------------------------------------------*/
extern int trace_sw; /*trace_sw is defined in debug.c*/
#define DEBUG
#ifdef DEBUG
#define GENERATE_STATEMENTS(statements) statem
ents
#else
#define GENERATE_STATEMENTS(statements) /*empty*/
#endif
/*trace a character variable*/
#define TC(user_text,character_variable) \
GENERATE_STATEMENTS(if (trace_sw) t_c(user_text,character_variable))
/*trace an integer variable*/
#define TI(user_text,integer_variable) \
GENERATE_STATEMENTS(if (trace_sw) t_i(user_text,integer_variable))
/*trace a long variable*/
#define TL(user_text,long_variable)
\
GENERATE_STATEMENTS(if (trace_sw) t_l(user_text,long_variable))
/*trace an unsigned variable*/
#define TU(user_text,unsign_variable) \
GENERATE_STATEMENTS(if (trace_sw) t_u(user_text,unsign_variable))
/*trace a double variable*/
#define TD(user_text,double_variable) \
GENERATE_STATEMENTS(if (trace_sw) t_d(user_text,double_variable))
/*trace a float variablle*/
#define TF(user_text,float_variable) \
G
ENERATE_STATEMENTS(if (trace_sw) t_f(user_text,float_variable))
/*trace a string variable*/
#define TS(user_text,string_variable) \
GENERATE_STATEMENTS(if (trace_sw) t_s(user_text,string_variable))
typedef struct
/*structure used by the inkey() keyboard function*/
{
char char1; /*inkey() returns a character, or zero into this field*/
char char2; /*if char1 is zero, inkey() returns the extended code here*/
}
TKB;
/*----------------------------END DEB
UG.H--------------------------------*/
<TAU>DEBUG.C:
176 lines
/*-------------------------DEBUG.C-----------------------------------------
* DEBUG.C C language symbolic debugger.
*
* (c) Copyright 1985 by Thomas D. Webb.
* All rights reserved.
* Permission is granted for unlimited personal, non-commercial use only.
*
-------------------------------------------------------------------------*/
#include <stdio.h>
#include <debug.h>
extern int CRTBUF(); /*external routine saves and restores cr
t buffer*/
#define CONTROL_KEY 68 /*fkey 10 used to toggle trace display on and off*/
#define VOID
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define SAVE 0 /*Used by CRTBUF*/
#define REPLACE 1
/*Used by CRTBUF*/
#define BLANK ' '
#define MAX_ROWS 24
#define MAX_COLUMNS 80
#define BUFFER_SIZE 4000 /*size of crt buffer save area*/
int trace_sw = OFF; /*turns trace table display on/off*/
static int first_time = TRUE;
c
har user_data[MAX_COLUMNS / 2]; /*users data, in trace table format*/
typedef struct tchr_attr /*structure used to address the video..*/
{ /*..character and attribute bytes*/
char chr;
char attr;
}
TCHR_ATTR;
static char save_buffer[BUFFER_SIZE]; /*crt buffer save area*/
static TCHR_ATTR trace_table[MAX_ROWS+2][MAX_COLUMNS]; /*the trace table*/
/*-----------------------------------------------------------------------*/
TKB *inkey()
/*bdos call to keyboard buffer returns a character..*/
{ /*..in kb.char1, or, if kb.char1 is binary zero, */
/*..an extended code in kb.char2*/
#define DOSFUNCTION 0x7 /* 0x7 = console input with echo*/
#def
ine DOSPARM 0x0 /* no parm is required */
TKB kb_rec; /*two-character work area used to receive..*/
/*..the characters from the keyboard*/
kb_rec.char1 = kb_rec.char2 = NULL;
kb_rec.char1 = bdos(DOS
FUNCTION,DOSPARM);
if (kb_rec.char1 == 0) /*IBM PC extended code*/
{
kb_rec.char2 = bdos(DOSFUNCTION,DOSPARM);
if (kb_rec.char2 == CONTROL_KEY) /*key that controls the trace*/
(trace_sw == ON) ? (t
race_sw = OFF) : (trace_sw = ON);
}
return(&kb_rec);
}/*inkey*/
/*-----------------------------------------------------------------------*/
VOID wait() /* routine to cause a wait */
{ /*
waits for the user to press a key*/
inkey(); /*the key value is discarded*/
} /* wait */
/*-----------------------------------------------------------------------*/
VOID init_table() /*initialize
the trace_table*/
{
int i,j;
static char trace_msg[] =
{
"Trace table...Press any key to return...Press F10 to suppress trace" };
for (i = 0; i < MAX_ROWS +2; i++)
for (j = 0; j < MAX_COLUMNS; j++)
{
trace_table[i][j
].chr = BLANK;
trace_table[i][j].attr = 0x7;
}
for (i = 0; i < sizeof(trace_msg); i++)
trace_table[0][i].chr = trace_msg[i];
} /* init_table */
/*-----------------------------------------------------------------------*/
VO
ID display_trace(user_text,user_data) /* display the trace table */
char user_text[];
char user_data[];
{
int i,j;
if (first_time) /*initialize the trace table*/
{
init_table();
first_time = FALSE;
}
movmem(&trace_table[2],&trace_table[1], /*bump the trace table*/
sizeof(trace_table) - 160);
for (i = 0; i < MAX_COLUMNS; i++) /*init last row of trace table*/
{
trace_table[MAX_ROWS][i].chr = BLANK;
trace_table[MAX_ROWS][i].attr = 0x7; /*normal attribute*/
} /*move user string to trace table*/
for (i = 0; (i < MAX_COLUMNS / 2) && (user_text[i] != NULL); i++)
trace_table[MAX_ROWS][i].chr = us
er_text[i];
for (i = MAX_COLUMNS / 2,j = 0; /*move user data to trace table*/
(i < MAX_COLUMNS) && (user_data[j] != NULL); i++,j++)
trace_table[MAX_ROWS][i].chr = user_data[j];
CRTBUF(SAVE,save_buffer); /* save
the user's crt buffer */
CRTBUF(REPLACE,trace_table); /* display the trace table */
wait(); /*wait while the user views the trace table*/
CRTBUF(REPLACE,save_buffer); /*restore the user's crt buffer */
} /* display_trace */
/*-----------------------------------------------------------------------*/
VOID t_c(user_text,character_variable) /*trace a character*/
char user_text[];
char character_variable;
{
if (character_variable == BLANK)
strcpy(
user_data,"BLANK char");
else if (character_variable == NULL)
strcpy(user_data,"NULL char");
else sprintf(user_data,"%c",character_variable);
display_trace(user_text,user_data);
}/*t_c*/
/*-------------------------------------------------
----------------------*/
VOID t_i(user_text,integer_variable) /*trace an integer*/
char user_text[];
int integer_variable;
{
sprintf(user_data,"%d",integer_variable);
display_trace(user_text,user_data);
}/*t_i*/
/*--------------------------------
---------------------------------------*/
VOID t_l(user_text,long_variable) /*trace a long integer*/
char user_text[];
long int long_variable;
{
sprintf(user_data,"%ld",long_variable);
display_trace(user_text,user_data);
}/*t_i*/
/*--------------
---------------------------------------------------------*/
VOID t_u(user_text,unsign_variable) /*trace an unsigned integer*/
char user_text[];
unsigned unsign_variable;
{
sprintf(user_data,"%u",unsign_variable);
display_trace(user_text,user_data
);
}/*t_u*/
/*-----------------------------------------------------------------------*/
VOID t_f(user_text,float_variable) /*trace a float*/
char user_text[];
double float_variable;
{
sprintf(user_data,"%f",float_variable);
display_trace(user_tex
t,user_data);
} /* t_f */
/*-----------------------------------------------------------------------*/
VOID t_d(user_text,double_variable) /*trace a double*/
char user_text[];
double double_variable;
{
sprintf(user_data,"%f",double_variable);
displa
y_trace(user_text,user_data);
} /* t_d */
/*-----------------------------------------------------------------------*/
VOID t_s(user_text,string_variable) /*trace a string*/
char user_text[];
char string_variable[];
{
int i, all_blanks;
if (string_v
ariable[0] == NULL) /*if string starts with a null char*/
{
strcpy(user_data,"NULL STRING");
display_trace(user_text,user_data);
return;
}
for (i = 0,all_blanks = TRUE;(i < MAX_COLUMNS /2) &&
(string_varia
ble[i] != NULL);i++)
{
user_data[i] = string_variable[i]; /*move in the string*/
if (string_variable[i] != BLANK) all_blanks = FALSE;
}
if (all_blanks)
strcpy(user_data,"BLANK STRING");
else user_data[
i] = NULL;
display_trace(user_text,user_data);
} /* t_s */
/*-------------------------END DEBUG.C-----------------------------------*/
<TAU>DRIVER.C:
54 lines
/*------------------------------DRIVER.C-----------------------------------
* DRIVER.C Rou
tines to illustrate the use of the symbolic debugger.
*
*
*------------------------------------------------------------------------*/
#include <stdio.h>
#include <debug.h>
/*-----------------------------------------------------------------------*/
func2()
/* this illustrates a typical application of the debugger: */
{ /* 1. record the entry into a function */
/* 2. record the program variables as they change */
/* 3. record the exit from the function */
in
t small_number;
long big_number;
TS("enter func2","-------------------");
for (small_number = 0, big_number = 0L; small_number < 5; small_number++)
{
big_number += small_number *10;
TI("small_number:",small_number);
TL("big_number:", big_number);
}
TS("exit func2","^^^^^^^^^^^^^^^^^^^");
} /*func2*/
/*-----------------------------------------------------------------------*/
func1() /*illustrate the use of all of the types of traces*/
{
char a = 'A';
int j = 123;
int *j_ptr = &j;
long k = 456789;
float f = 12.978;
static char string[] = "hello, world";
TS("enter func1","-------------------");
TC("Character test",a);
TI("Integer test",j);
TL("Long test",k);
TU("Unsigned test",j_ptr);
TF("Float test",f);
TD("Double test",123456.789012);
TS("String test",string);
TS("exit func1","^^^^^^^^^^^^^^^^^^^^");
} /*func1*/
/*-----------------------------------------------------------------------*/
main()
{
printf("Debug driver version 02 start\n");
printf("Press F10 to start trace\n");
inkey();
func1();
func2();
printf("Debug driver end\n");
} /*main*/
/*--------------------------END DRIVER.C---------------------------------*/